//
// Created by Administrator on 2023/11/17.
//
#include "iostream"


using namespace std;

const int N = 1e5 + 10;
int n, tt = -1;//tt是栈的top指针
int A[N], S[N];


int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> A[i];

    for (int i = 0; i < n; ++i) {

        while (S[tt] >= A[i] && tt != -1)
            tt--;

        if (tt == -1)
            cout << "-1 ";
        else
            cout << S[tt] << ' ';

        S[++tt] = A[i];

    }

}